Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
JavaScript ES6 FastAPI Fetch results in "Type Error"

i try to set up an simple API on my local machine with FastAPI Backend and then fetch it with a simple JS Script. I googled the whole day, but still can't figure out the issue.

I could bet i missed something.

The FastAPI Backend looks like:

from fastapi import FastAPI
import uvicorn

from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()

origins = [
    "http://localhost",
    "http://localhost:8000",
    "http://127.0.0.2",
    "http://127.0.0.2:8000"
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=False,
    allow_methods=["*"],
    allow_headers=["*"],
)


@app.get("/")
async def root():
    return {"Message": "Root"}

    
if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.2", port="8000")

And Js Script looks like:

async function getRoot() {

fetchAdresse = 'http://127.0.0.2:8000';


const response = await fetch(fetchAdresse, {
    method: 'GET',
    headers: {
        accept: 'html/text',
    },
});

console.log(response);

}

getRoot();

Response is always the same:

Uncaught TypeError TypeError: Failed to fetch

On the other Hand Server response is:

INFO:     127.0.0.1:60927 - "GET / HTTP/1.1" 200 OK
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

"Failed to fetch" can mean many different things.

I suggest you open up the network tab in inspect mode. It should look like this:Devtools inspect network tab When the program fetches, there should be a request going out, and you should see it there. You can then have a look at the "status", or click on the request for a clearer error and then Google that.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda